<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>可被 K 整除的最小整数</title>
</head>
<body>
  <script>
    function fn(k) {
      // 如果 k 是偶数或者是 5 的倍数，则无法整除，直接返回 -1
      if (k % 2 === 0 || k % 5 === 0) {
        return -1;
      }
      let resid = 1 % k, len = 1
      while (resid !== 0) {
        resid = (resid * 10 + 1) % k
        len++
      }
      return len
    }
    console.log(fn(1))
  </script>
</body>
</html>